﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FutureOpen.Web.Pages;
using FutureOpen.Core;
using FutureOpen.Core.func;
using FutureOpen.Core.func.util;
using FutureOpen.Core.func.db;
using System.Text;
using System.Text.RegularExpressions;

public partial class MyJobTags : PageBase
{
    private int uid;

    private MyTagJob tagutil = new MyTagJob();
    protected void Page_Load(object sender, EventArgs e)
    {
        base.PageInit();
        if (this.usrid > 0)
        {
            uid = this.usrid;

        }
        else if (base.IsLogin())
        {
            uid = MyUsr;
        }

        if (!IsPostBack && uid > 0)
        {
            this.AspNetPager1.RecordCount = tagutil.GetTagCount(this.uid);
            LoadTags(0, 20);
        }
    }

    private void LoadTags(int start, int count)
    {
        IList<Tagjob> tags = tagutil.GetUsrTags(this.uid, start, count);
        this.dlTags.DataSource = tags;
        this.dlTags.DataBind();

        /*
        string pager = Request.QueryString["p"];
        int iPage = 1;
        if (pager != null) iPage = int.Parse(pager);

        int uid = this.MyUsr.Usr_id;
        MyTagJob mtj = new MyTagJob(uid);
        IList<Tagjob> ListTJ = mtj.GetUsrTags();

        int start = (iPage - 1) * psize;
        int i=0;
        StringBuilder sb = new StringBuilder();
        while (i < psize && start < ListTJ.Count)
        {
            Tagjob tj = ListTJ[start];
            start++;
            i++;
            string seq = start.ToString();
            string trend = null;
            if (tj.Tagjob_bin_day > tj.Tagjob_bin_week) trend = "1";
            else if (tj.Tagjob_bin_day < tj.Tagjob_bin_week) trend = "-1";
            else trend = "0";
            sb.Append(string.Format(strformat, tj.Tagjob_text, seq, trend, tj.Tagjob_bin_day.ToString(),tj.Tagjob_bin_week.ToString(), tj.Tagjob_count.ToString(), HttpUtility.UrlEncode(tj.Tagjob_text)));
        }
        this.ltTags.Text = sb.ToString();
        int ePage = (int)Math.Ceiling((double)ListTJ.Count / psize);
        this.LtPages.Text = GetTagContext(URL, iPage, ePage);
        */
    }

    private string EncodeURL(string url, string title)
    {
        return StringUtil.EncodeNoDecURL(url, title);
    }
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        LoadTags((e.NewPageIndex - 1) * 20, 20);
    }

    public int GetLevel(Object p1, Object p2)
    {
        int day = Int32.Parse(p1.ToString());
        int week = Int32.Parse(p2.ToString());

        int avg = week / 7;
        if (day > 1.2 * avg)
        {
            return 2;
        }
        else if (day < 0.8 * avg)
        {
            return 1;
        }
        return 0;

    }

    public string EncodeText(object obj)
    {
        return HttpUtility.UrlEncode(obj.ToString());
    }
}
